import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
    public static void main(String[] args) throws  Exception{
        //可以在CyclicBarrier中设置优先执行线程
        final   CyclicBarrier cyclicBarrier=new CyclicBarrier(7, new Runnable() {
            public void run() {
                System.out.println("-----集齐七颗龙珠，召唤神龙-----");
            }
        });
        ExecutorService executorService=Executors.newCachedThreadPool();
        for(int i=0;i<7;i++){
            final  int temp=i;
            executorService.execute(()->{
                try {
                    System.out.println(Thread.currentThread().getName()+"-----集齐第 "+(temp+1)+" 颗龙珠-----");
                    cyclicBarrier.await();
                }catch (Exception ex){

                }
            });
        }
    }
}
